package com.etc;


import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.LazyOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;


import java.io.File;
import java.io.IOException;

public class DataJob {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration configuration = new Configuration();
        Job job = Job.getInstance(configuration);

        job.setJarByClass(DataJob.class);
        job.setMapperClass(DataMapper.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(NullWritable.class);

        File file = new File("E:\\数据清洗\\output");
        if (file.exists()){
            FileUtil.fullyDelete(file);
        }
        // 避免生成默认的part-m-00000等文件，因为，数据已经交给MultipleOutputs输出了
        LazyOutputFormat.setOutputFormatClass(job, TextOutputFormat.class);

        FileInputFormat.setInputPaths(job,new Path("E:\\数据清洗\\input--4天的未清洗的数据\\20170814new"));
        FileOutputFormat.setOutputPath(job,new Path("E:\\数据清洗\\output"));

        job.setNumReduceTasks(1);

        System.exit(job.waitForCompletion(true) ? 0 :1 );
    }
}
